package com.project.livetv.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.project.livetv.R;
import com.project.livetv.bean.LatestBean;
import com.project.livetv.config.NetConfig;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by li on 2016/5/10.
 */
public class MyHotTabAdapter extends MyBaseAdapter<LatestBean.LivesBean> {
    List<LatestBean.LivesBean> list;
    Context mContext;
    public MyHotTabAdapter(Context context, List<LatestBean.LivesBean> list) {
        super(context, list);
        this.list=list;
        mContext=context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder;
        if(convertView==null){
            convertView= LayoutInflater.from(mContext).inflate(R.layout.hot_listview_layout,parent,false);
            holder=new MyViewHolder(convertView);
            convertView.setTag(holder);
        } else{
            holder= (MyViewHolder) convertView.getTag();
        }
        Log.d("tag","getview"+list.size()+"  "+position);
        LatestBean.LivesBean.CreatorBean creator = list.get(position).getCreator();
        holder.user_name.setText(creator.getNick());
        holder.user_address.setText(list.get(position).getCity());
        holder.user_number.setText(list.get(position).getOnline_users() + "  在看");
        String url_img = creator.getPortrait();
        String imgUrl = NetConfig.MAIN_TV_HOT_IMAGE1+url_img+NetConfig.MAIN_TV_HOT_IMAGE2;
        x.image().bind(holder.user_info_icon,imgUrl);
        ImageOptions options = new ImageOptions.Builder().setCircular(true).build();
        x.image().bind(holder.user_icon,imgUrl,options);
        return convertView;
    }

    class MyViewHolder{
         TextView user_name,user_address,user_number;
        ImageView user_icon,user_info_icon;
        public MyViewHolder(View view){
            user_name= (TextView) view.findViewById(R.id.user_name);
            user_address= (TextView) view.findViewById(R.id.user_address);
            user_number= (TextView) view.findViewById(R.id.user_number);
            user_icon= (ImageView) view.findViewById(R.id.user_icon);
            user_info_icon= (ImageView) view.findViewById(R.id.user_info_icon);
        }
    }
}
